<template>
  <div class="right-panel">
    <div class="control-section">
      <!-- 对话 -->
      <div class="chat-container">
        <div
          class="messages"
          :style="{ height: isSending ? '450px' : '500px' }"
        >
          <div
            v-for="(message, index) in messages"
            :key="index"
            :class="[
              'message',
              message.sender === '用户' ? 'message-user' : 'message-ai',
            ]"
          >
            <template v-if="message.sender === '用户'">
              <div class="message-box message-box-user">
                <!-- 显示选中的文件 -->
                <div v-if="message.files.length" class="check-file-list">
                  <div
                    v-for="(file, fileIndex) in message.files"
                    :key="fileIndex"
                    class="file-item"
                  >
                    <div class="file-icon">
                      <img src="@/assets/img/doc-icon.png" alt="" />
                    </div>
                    <div class="file-details">
                      <div class="file-name">{{ file.fileName }}</div>
                      <div class="file-size">{{ file.fileSize }}</div>
                    </div>
                  </div>
                </div>
                <div class="user-message-content">
                  <div v-html="message.text"></div>
                </div>
              </div>
              <img :src="userAvatar" class="user-avatar" />
            </template>
            <template v-else>
              <img :src="aiAvatar" class="ai-avatar" />
              <div class="message-box message-box-ai">
                <!-- 显示选中的文件 -->
                <div v-if="message.files.length" class="check-file-list">
                  <div
                    v-for="(file, fileIndex) in message.files"
                    :key="fileIndex"
                    class="file-item"
                  >
                    <div class="file-icon">
                      <img src="@/assets/img/doc-icon.png" alt="" />
                    </div>
                    <div class="file-details">
                      <div class="file-name">{{ file.fileName }}</div>
                      <div class="file-size">{{ file.fileSize }}</div>
                    </div>
                  </div>
                </div>
                <div class="message-content">
                  <!-- 当消息为空且正在发送时显示加载动画 -->
                  <div v-if="!message.text && isSending" class="loading-dots">
                    <span></span>
                    <span></span>
                    <span></span>
                  </div>
                  <div class="markdownContent" v-else>
                    <mdEditor
                      :toolbars="[]"
                      :footers="[]"
                      ref="mavonEditor"
                      class="mdEditor"
                      v-model="message.text"
                    />
                  </div>
                </div>
              </div>
            </template>
          </div>
        </div>

        <!-- 停止响应按钮 -->
        <div class="stop-response" v-if="isSending" @click="stopResponse()">
          <span @mouseover="stopHover = true" @mouseleave="stopHover = false">
            <img :src="stopHover ? stopImg1 : stopImg0" alt="" />
            停止响应
          </span>
        </div>

        <!-- 输入框 -->
        <div
          class="input-container"
          :style="{
            height: docsList && docsList.length > 0 ? '230px' : '130px',
          }"
        >
          <!-- 添加新对话 -->
          <!-- <div class="add-chat" @click="addChat()"><img src="@/assets/img/新增对话.png" alt=""></div> -->

          <!-- 展示上传文件 -->
          <div
            class="upload-file-list"
            :style="{
              padding: docsList && docsList.length > 0 ? '14px 18px 10px' : '0',
            }"
          >
            <div class="docs">
              <div class="doc-item" v-for="item in docsList" :key="item.id">
                <div class="close-btn">
                  <el-icon><Close /></el-icon>
                </div>
                <div class="doc-item-img">
                  <img src="@/assets/img/doc-icon.png" alt="" />
                </div>
                <div class="doc-item-info">
                  <span class="doc-item-title">{{ item.title }}</span>
                  <span class="doc-item-size">{{ item.size }}</span>
                </div>
              </div>
            </div>
          </div>

          <el-input
            class="sendInput"
            type="textarea"
            v-model="userInput"
            @keydown="handleKeyCode($event)"
            placeholder="请输入您想问的内容，按 Shift + Enter 换行"
            :style="{ border: 'none' }"
            :resize="'none'"
          />
          <div class="foot-btn">
            <div class="foot-left">
              <!-- 清空对话按钮 -->
              <div class="clear-chat" @click="clearChat()">
                <span
                  @mouseover="clearHover = true"
                  @mouseleave="clearHover = false"
                >
                  <img
                    :src="clearHover ? clearImg1 : clearImg0"
                    alt=""
                    style="width: 10px; height: 12px"
                  />
                  清空对话
                </span>
              </div>
              <!-- 上传 -->
              <div class="upload-btn">
                <el-upload
                  ref="upload"
                  class="upload-component"
                  action="/tes/experiment/course-review-fileupload"
                  :limit="1"
                  :show-file-list="false"
                  :before-upload="handleUpload"
                  :on-success="handleSuccess"
                >
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="支持上传文件：pdf，doc，xlsx，ppt，txt等"
                    placement="top"
                  >
                    <span>
                      <i class="iconfont icon-shangchuan1"></i>上传文件
                    </span>
                  </el-tooltip>
                </el-upload>
              </div>
            </div>
            <!-- 发送 -->
            <div class="foot-right">
              <el-button
                type="primary"
                :disabled="isSending"
                @click="sendMessage"
                class="send-button"
                >发送</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import clearImg0 from "@/assets/img/清空对话0.png";
import clearImg1 from "@/assets/img/清空对话1.png";
import stopImg0 from "@/assets/img/停止0.png";
import stopImg1 from "@/assets/img/停止1.png";
import aiAvatar from "@/assets/img/ai-answer.png";
import userAvatar from "@/assets/img/user.png";
export default {
  data() {
    return {
      uploadedFiles: [],
      userInput: "",
      messages: [
        {
          sender: "小红书推文写作助手",
          text: "我擅长为企业打造专属营销我擅长为企业打造专属营销属营销",
          files: [],
          isWelcome: true, // 添加标记表示这是欢迎语
        },
      ],
      aiAvatar,
      userAvatar,
      selectedFileIndex: [],
      isSelected: false, // 用于跟踪当前选择状态
      uploadLoading: false,
      eventSource: null,
      connectId: null,
      fileId: null,
      isSending: false,
      stopHover: false,
      clearHover: false,
      sessionId: "",
      sseUrl: "",
      clearImg0,
      clearImg1,
      stopImg0,
      stopImg1,
      docsList: [
        {
          id: 1,
          title: "小红书推文写作助手",
          size: "100KB",
        },
        {
          id: 2,
          title: "小红书推文写作助手111",
          size: "200KB",
        },
      ],
    };
  },
  created() {
    this.getFileList();
    this.getSessionId();
    this.getSSEUrl();
  },

  methods: {
    // 获取SSE地址
    getSSEUrl() {
      this.$axios.get("/tes/experiment/queryBaseUrl").then((res) => {
        if (res.data.code === 200) {
          this.sseUrl = res.data.data.socketUrl;
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    getSessionId() {
      const characters =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
      let result = "";
      for (let i = 0; i < 16; i++) {
        result += characters.charAt(
          Math.floor(Math.random() * characters.length)
        );
      }
      this.sessionId = result;
    },
    // 获取文件列表
    getFileList() {
      this.$axios
        .get("/tes/experiment/course-review-filelist?type=1")
        .then((res) => {
          if (res.data.code === 200) {
            this.uploadedFiles = res.data.data;
          }
        });
    },
    // 发送消息
    sendMessage() {
      if (this.userInput.trim() === "") {
        this.$message.error("请输入您想问的内容");
        this.userInput = "";
        return;
      }
      // if(!this.fileId) {
      //   this.$message.error('请选择文件');
      //   return;
      // }

      if (this.isSending) {
        this.$message.error("请等待上一次对话结束");
        return;
      }
      // 添加用户消息
      const newMessage = {
        sender: "用户",
        text: this.userInput.replace(/\n/g, "<br>"),
        files: this.selectedFileIndex.map((index) => this.uploadedFiles[index]),
      };
      this.messages.push(newMessage);

      // 添加AI消息占位
      const aiMessage = {
        sender: "小红书推文写作助手",
        text: "",
        files: [],
        isWelcome: false, // 标记这不是欢迎语
      };
      this.messages.push(aiMessage);

      // 建立 SSE 连接
      this.connectEventSource(newMessage.text);

      // 清空输入框和选中的文件
      this.userInput = "";
      // this.selectedFileIndex = [];
      this.isSending = true;

      // 滚动到最新消息
      this.$nextTick(() => {
        const messagesContainer = this.$el.querySelector(".messages");
        messagesContainer.scrollTop = messagesContainer.scrollHeight;
      });
    },

    // 建立sse连接
    connectEventSource(inputMessage) {
      const that = this;

      if (window.EventSource) {
        // 如果已经存在连接，先关闭
        if (this.eventSource) {
          this.eventSource.close();
        }

        this.eventSource = new EventSource(`${this.sseUrl}/tes/sse/connect`);

        this.eventSource.onmessage = function (event) {
          const connectId = event.lastEventId;
          const data = event.data;

          if (connectId === data) {
            // 获取到连接id后发送实际消息
            that.connectId = connectId;
            const params = {
              type: 1,
              connectId: connectId,
              prompt: inputMessage,
              sessionId: that.sessionId,
              // fileId: that.fileId
            };
            that.$axios
              .post("/tes/experiment/xhsWritingAndPDDWriting", params)
              .then((res) => {
                // console.log('消息发送成功:', res);
              })
              .catch((err) => {
                // console.error('消息发送失败:', err);
                that.$message.error("消息发送失败");
              });
          } else {
            // 处理返回的消息流
            let currentMessage = that.messages[that.messages.length - 1];

            // 处理特殊字符
            let processedData = data
              .replaceAll("↖emsp↘", " ")
              .replaceAll("↖br↘", "\n")
              .replaceAll("↖tab↘", "   ")
              .replaceAll("对话结束", "");

            // 更新markdown内容
            currentMessage.text += processedData;
            that.$nextTick(() => {
              // 滚动到底部
              const messagesContainer = that.$el.querySelector(".messages");
              messagesContainer.scrollTop = messagesContainer.scrollHeight;
            });

            if (data === "对话结束") {
              that.isSending = false;
              that.eventSource.close();
              that.eventSource = null;
            }
          }
        };

        this.eventSource.onerror = function (error) {
          // console.error('SSE 连接错误:', error);
          // that.$message.error('连接出错，请重试');
          that.eventSource.close();
          that.eventSource = null;
          that.isSending = false;
        };
      } else {
        this.$message.error("您的浏览器不支持 SSE，请更换浏览器");
        that.isSending = false;
      }
    },

    // 上传前
    handleUpload(file) {
      this.uploadLoading = this.$loading({
        lock: true,
        text: "上传中...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      const isDOC = file.name.endsWith(".doc") || file.name.endsWith(".docx");
      if (!isDOC) {
        this.$message.error("只能上传.doc或.docx格式的文件！");
        this.uploadLoading.close();
        return false;
      }
    },

    // 上传成功
    handleSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.getFileList();
        this.uploadLoading.close();
        // 重置上传组件
        this.$refs.upload.clearFiles();
      } else {
        this.$message.error(response.msg);
        this.uploadLoading.close();
      }
    },

    // 删除文件
    delFile(id) {
      this.$axios
        .delete("/tes/experiment/course-review-filedelete?fileId=" + id)
        .then((res) => {
          if (res.data.code === 200) {
            this.$message.success("删除成功");
            // 如果删除的是当前选中的文件，重置选择状态
            if (this.fileId === id) {
              this.fileId = null;
              this.selectedFileIndex = [];
            }
            this.getFileList();
          }
        });
    },

    // 左右滑动文件列表
    scrollLeft() {
      const stepBox = this.$refs.stepBox;
      stepBox.scrollBy({
        left: -200,
        behavior: "smooth",
      });
    },
    scrollRight() {
      const stepBox = this.$refs.stepBox;
      stepBox.scrollBy({
        left: 200,
        behavior: "smooth",
      });
    },

    // 复制消息
    copyMessage(text) {
      try {
        if (navigator.clipboard) {
          navigator.clipboard.writeText(text).then(() => {
            this.$message.success("消息已复制到剪贴板");
          });
        } else {
          // 降级处理 - 使用传统方法
          const textarea = document.createElement("textarea");
          textarea.value = text;
          document.body.appendChild(textarea);
          textarea.select();
          document.execCommand("copy");
          document.body.removeChild(textarea);
          this.$message.success("消息已复制到剪贴板");
        }
      } catch (err) {
        this.$message.error("复制失败，请手动复制");
      }
    },

    // 删除消息
    deleteMessage(index) {
      this.messages.splice(index, 1);
    },

    // 引用消息
    quoteMessage(text) {
      this.userInput = "";
    },

    // 重新生成消息
    resetSend(index) {
      // 删除当前AI回复的消息
      this.messages.splice(index, 1);

      // 获取上一条用户消息
      const userMessage = this.messages[index - 1];

      // 添加新的AI消息占位
      const aiMessage = {
        sender: "小红书推文写作助手",
        text: "",
        files: [],
        isWelcome: false, // 标记这不是欢迎语
      };
      this.messages.push(aiMessage);

      // 重新建立 SSE 连接并发送消息
      this.connectEventSource(userMessage.text);
      this.isSending = true;

      // 滚动到最新消息
      this.$nextTick(() => {
        const messagesContainer = this.$el.querySelector(".messages");
        messagesContainer.scrollTop = messagesContainer.scrollHeight;
      });
    },

    // 换行处理
    handleKeyCode(event) {
      if (event.keyCode === 13) {
        if (event.shiftKey) {
          return;
        } else {
          event.preventDefault();
          this.sendMessage();
        }
      }
    },

    // 选中文件
    toggleFileSelection(index, id) {
      // 更新选中状态
      this.selectedFileIndex = [index];
      this.fileId = id;
    },

    toggleSelection() {
      this.isSelected = !this.isSelected; // 切换选择状态
    },

    addChat() {
      if (this.isSending) {
        this.$message.error("请等待上一次对话结束");
        return;
      }

      // 在最后一条消息后添加分割线
      const divider = document.createElement("div");
      divider.style.textAlign = "center";
      divider.style.width = "80%";
      divider.style.color = "#999";
      divider.style.margin = "10px 0";
      divider.innerText =
        "-----------------------------------------以下是新消息-----------------------------------------";

      const messagesContainer = this.$el.querySelector(".messages");
      messagesContainer.appendChild(divider);
      // 清空消息列表
      // this.messages = [];

      // 添加新的欢迎语
      this.messages.push({
        sender: "小红书推文写作助手",
        text: "我擅长为企业打造专属营销内容，让你的产品更具吸引力。",
        files: [],
        isWelcome: true, // 添加标记表示这是欢迎语
      });
      // 清空其他状态
      this.userInput = "";
      this.selectedFileIndex = [];
      // this.quotedText = "";
      this.fileId = null;
      this.getSessionId();
      // 滚动到最新消息
      this.$nextTick(() => {
        const messagesContainer = this.$el.querySelector(".messages");
        messagesContainer.scrollTop = messagesContainer.scrollHeight;
      });
    },

    // 停止响应
    stopResponse() {
      if (this.connectId) {
        this.$axios
          .get(`/tes/experiment/stop/${this.connectId}`)
          .then((res) => {
            if (res.data.code === 200) {
              this.$message.success("已停止响应");
              this.isSending = false;
              if (this.eventSource) {
                this.eventSource.close();
                this.eventSource = null;
              }
            }
          })
          .catch((err) => {
            console.error("停止响应失败:", err);
            this.$message.error("停止响应失败");
          });
      }
    },

    // 清空对话方法
    clearChat() {
      if (this.isSending) {
        this.$message.error("请等待上一次对话结束");
        return;
      }

      // 清空所有分割线
      const messagesContainer = this.$el.querySelector(".messages");
      const dividers = messagesContainer.querySelectorAll(
        'div[style*="text-align: center"]'
      );
      dividers.forEach((divider) => divider.remove());

      // 只保留欢迎语
      this.messages = [
        {
          sender: "小红书推文写作助手",
          text: "我擅长为企业打造专属营销内容，让你的产品更具吸引力。",
          files: [],
          isWelcome: true,
        },
      ];

      // 清空其他状态
      this.userInput = "";
      this.selectedFileIndex = [];
      this.quotedText = "";
      this.fileId = null;
    },
  },
};
</script>

<style lang="scss" scoped>
.right-panel {
  width: 100%;
  max-height: 650px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;

  .control-section {
    padding: 10px 20px 0;
    background-color: #f3f5fa;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;

    .upload-area {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .addFiles {
        width: 65px;
        height: 65px;
        background: #ffffff;
        box-shadow: 1px 2px 6px 0px rgba(0, 0, 0, 0.11);
        border-radius: 10px;
        border: 1px solid #e5e5e5;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        i {
          font-size: 18px;
          margin-bottom: 5px;
        }
        &:hover {
          color: #1c4fe5;
        }
      }
      .file-list-content {
        width: 100%;

        position: relative;
        .arrow-left {
          position: absolute;
          left: 15px;
          top: 30%;
          width: 30px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          border-radius: 50%;
          background-color: rgba(0, 0, 0, 0.5);
          color: #fff;
          z-index: 999;
          cursor: pointer;
          &:hover {
            background-color: rgba(0, 0, 0, 0.7);
          }
        }
        .arrow-right {
          position: absolute;
          right: -35px;
          top: 30%;
          width: 30px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          border-radius: 50%;
          background-color: rgba(0, 0, 0, 0.5);
          color: #fff;
          z-index: 999;
          cursor: pointer;
          &:hover {
            background-color: rgba(0, 0, 0, 0.7);
          }
        }
        .file-list {
          position: relative;
          margin-left: 50px;
          width: 1000px;
          height: 80px;
          overflow-x: hidden;
          display: flex;
          justify-content: flex-start;
          align-items: center;
          li {
            position: relative;
            flex-shrink: 0;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            width: 200px;
            height: 65px;
            padding: 15px 18px;
            background: #ffffff;
            box-shadow: 1px 2px 6px 0px rgba(0, 0, 0, 0.11);
            border-radius: 10px;
            margin-right: 20px;
            box-sizing: border-box;
            cursor: pointer;
            .removeFile {
              position: absolute;
              top: -7px;
              right: -7px;
              z-index: 99;
            }
            .file-icon {
              width: 25px;
              height: 33px;
              img {
                width: 100%;
              }
            }
            .file-details {
              display: flex;
              flex-direction: column;
              align-items: flex-start;
              margin-left: 17px;
              .file-name {
                font-size: 14px;
                color: #000000;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                max-width: 120px;
              }
              .file-size {
                font-size: 12px;
                color: #909090;
                margin-top: 10px;
              }
            }
          }
        }
      }
    }

    .chat-container {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: calc(100vh - 280px);
      padding-bottom: 10px;
      position: relative;
      box-sizing: border-box;

      .messages {
        width: 100%;
        padding: 10px;
        min-height: 0;
        max-height: 100%;
        overflow-y: auto;
      }

      .message {
        display: flex;
        margin: 10px 0;
        box-sizing: border-box;
        width: 100%;
      }

      .message-user {
        justify-content: flex-end;
      }

      .message-ai {
        justify-content: flex-start;
      }

      .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        margin-left: 10px;
      }

      .ai-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        margin-right: 10px;
      }

      .message-box {
        max-width: calc(100% - 120px);
        border-radius: 10px;
        word-wrap: break-word;
        display: flex;
        flex-direction: column;
        .message-content {
          background-color: #fff;
          border-radius: 10px;
          line-height: 1.5;
          overflow: hidden;

          .markdownContent {
            .mdEditor {
              border: none;
              height: auto;
              // 隐藏头部工具栏
              // :deep(.md-editor-toolbar-wrapper) {
              //   display: none;
              //   padding: 0;
              // }
              // 隐藏底部
              // :deep(.md-editor-footer) {
              //   display: none;
              // }
              // 隐藏左侧编辑区
              :deep(.md-editor-input-wrapper) {
                display: none;
              }
              // 隐藏中间分割线
              :deep(.md-editor-resize-operate) {
                width: 0;
              }
              :deep(.md-editor-content-wrapper) {
                width: 100% !important;
              }
              :deep(.md-editor-content) {
                display: block;
              }
            }
          }
        }
        .user-message-content {
          max-width: 100%;
          padding: 10px 20px;
          background-color: #e0e4f9;
          border-radius: 10px;
          line-height: 1.5;

          .quote-box {
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 超出部分隐藏 */
            text-overflow: ellipsis; /* 超出部分用省略号表示 */
            margin-bottom: 5px; /* 引用与消息内容之间的间距 */
            padding: 5px; /* 引用盒子的内边距 */
            background-color: #f3f4fa; /* 引用盒子的背景色 */
            border-radius: 5px; /* 圆角 */
          }
        }
      }

      .message-box-user {
        align-items: flex-end;
      }

      .message-box-ai {
        align-items: flex-start;
      }

      .check-file-list {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
        .file-item {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          width: 200px;
          height: 65px;
          padding: 15px 18px;
          background: #ffffff;
          box-shadow: 1px 2px 6px 0px rgba(0, 0, 0, 0.11);
          border-radius: 10px;
          margin-right: 20px;
          margin-bottom: 10px;
          box-sizing: border-box;
          .file-icon {
            width: 25px;
            height: 33px;
            img {
              width: 100%;
            }
          }
          .file-details {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            margin-left: 17px;
            .file-name {
              font-size: 14px;
              color: #000000;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              max-width: 120px;
            }
            .file-size {
              font-size: 12px;
              color: #909090;
              margin-top: 10px;
            }
          }
        }
      }

      .action-buttons {
        max-width: 100%; /* 限制消息内容的最大宽度 */
        display: flex;
        justify-content: space-between;
        align-items: center;
        .item-right {
          flex: 1;
          text-align: right;
        }
      }
    }

    .input-container {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      max-width: 100%;
      margin-top: 10px;
      border-radius: 8px;
      height: 130px;
      min-height: 100px;
      background-color: #fff;
      border: 1px solid #e5e5e5;

      // 添加媒体查询，处理150%缩放的情况
      @media screen and (max-width: 1200px),
        screen and (-webkit-min-device-pixel-ratio: 1.5),
        screen and (min-resolution: 144dpi) {
        width: 90%;
        margin-left: auto;
        margin-right: auto;
      }
      .upload-file-list {
        padding: 14px 18px 10px;
        .docs {
          display: flex;
          align-items: center;
          gap: 10px;
          .doc-item {
            position: relative;
            padding: 8px 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            width: 185px;
            height: 55px;
            background: #f2f2f2;
            border-radius: 10px;
            cursor: pointer;
            box-sizing: border-box;
            .close-btn {
              display: flex;
              align-items: center;
              justify-content: center;
              position: absolute;
              top: 7px;
              right: 7px;
              width: 12px;
              height: 12px;
              background: #727272;
              border-radius: 50%;

              .el-icon {
                font-size: 8px;
                color: #fff;
                cursor: pointer;
              }
            }
            .doc-item-img {
              flex-shrink: 0;
              width: 30px;
              height: 40px;
              img {
                width: 100%;
                height: 100%;
                object-fit: cover;
              }
            }
            .doc-item-info {
              flex: 1;
              display: flex;
              flex-direction: column;
              align-items: flex-start;
              justify-content: center;
              .doc-item-title {
                font-size: 12px;
                color: #181818;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                max-width: 96px;
              }
              .doc-item-size {
                font-size: 12px;
                color: #7c7c7c;
              }
            }
          }
        }
      }
      :deep(.el-textarea__inner) {
        border: none;
        height: 80px;
        box-shadow: none;
      }
      .add-chat {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: -50px;
        width: 40px;
        height: 40px;
        background: #ffffff;
        border-radius: 50%;
        border: 1px solid #e5e5e5;
        text-align: center;
        line-height: 40px;
        cursor: pointer;
        z-index: 1;

        // 在大屏幕缩放时调整位置
        @media screen and (max-width: 1200px),
          screen and (-webkit-min-device-pixel-ratio: 1.5),
          screen and (min-resolution: 144dpi) {
          left: -50px;
        }

        img {
          width: 17px;
          height: 17px;
          vertical-align: middle;
        }
      }
    }

    input {
      padding: 10px;
      width: calc(100% - 50px); /* 留出按钮的空间 */
      border: 1px solid #ccc;
      border-radius: 5px; /* 圆角 */
    }

    .stop-response {
      display: flex;
      justify-content: center;
      align-items: center;
      font-family: Microsoft YaHei;
      font-size: 14px;
      cursor: pointer;
      &:hover {
        color: #1c4fe5;
      }

      span {
        // padding: 5px 7px;
        width: 108px;
        height: 30px;
        background: #ffffff;
        box-shadow: 0px 2px 14px 0px rgba(43, 85, 191, 0.19);
        border-radius: 6px;
        border: 1px solid #e9ebf2;
        font-size: 14px;
        line-height: 32px;
        text-align: center;
        i {
          margin-right: 5px;
        }
        &:hover {
          color: #1c4fe5;
          border: 1px solid #1c4fe5;
        }
      }
    }
    .foot-btn {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      background: #ffffff;
      padding: 0 15px 10px;
      box-sizing: border-box;
      .foot-left {
        display: flex;
        align-items: center;
        .clear-chat {
          text-align: center;
          background: #ffffff;
          font-size: 12px;
          color: #7c8aa7;
          cursor: pointer;

          // 在大屏幕缩放时调整位置
          @media screen and (max-width: 1200px),
            screen and (-webkit-min-device-pixel-ratio: 1.5),
            screen and (min-resolution: 144dpi) {
            margin-left: 40px;
          }
          &:hover {
            color: #1c4fe5;
          }
        }

        .upload-btn {
          margin-left: 10px;
          margin-bottom: 3px;
          span {
            font-size: 12px;
            color: #7c8aa7;
            i {
              font-size: 12px;
              margin-right: 3px;
            }
            &:hover {
              color: #1c4fe5;
              background-color: #fff;
            }
          }
        }
      }
      .foot-right {
        display: flex;
        justify-content: flex-end;
        .send-button {
          background-color: #1c4fe5; /* 按钮背景色 */
          border: none;
          background: #2a6ee9;
          border-radius: 10px;
          text-align: center;
          cursor: pointer; /* 鼠标指针 */
        }
        .send-button img {
          width: 20px; /* 图标宽度 */
          height: 20px; /* 图标高度 */
        }

        .send-button:hover {
          background-color: #1c4fe5; /* 悬停时的背景色 */
        }
      }
    }
  }
  // 修改滚动条样式
  ::-webkit-scrollbar {
    width: 5px;
    background-color: #f5f5f5;
  }
  ::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
  }
}

.selected-file {
  border: 1px solid #cdd2df; // 设置选中时的边框颜色
  .circle {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 12px;
    height: 12px;
    z-index: 99;
  }
}

.circle {
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 12px;
  height: 12px;
  z-index: 99;
}

.quote-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: #f3f4fa;
  border-radius: 8px;
  margin-bottom: 10px; // 与输入框的间距
}

.quote-box-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #e0e4f9;
  border-radius: 8px;
  margin-bottom: 10px; // 与输入框的间距
}

.quoted-content {
  flex: 1; // 让内容占据剩余空间
  margin-right: 10px; // 右侧间距
  overflow: hidden; // 超出部分隐藏
  white-space: nowrap; // 不换行
  text-overflow: ellipsis; // 超出部分用省略号表示
}

.quoted-content-user {
  flex: 1; // 让内容占据剩余空间
  overflow: hidden; // 超出部分隐藏
  white-space: nowrap; // 不换行
  text-overflow: ellipsis; // 超出部分用省略号表示
  color: #6670a5;
}

.loading-dots {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 20px;

  span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #1c4fe5;
    margin-right: 5px;
    animation: loading 1.4s infinite ease-in-out both;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }
  }
}

@keyframes loading {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}
</style>
